<!DOCTYPE HTML>
<html>
<head>
<?php
$isEditPost=false;
$postid=0;
$postLocationAdd="";
if(isset($_REQUEST["p"]) && is_numeric(trim($_REQUEST["p"])) && trim($_REQUEST["p"])==1){
    $isEditPost=true;
}
if(isset($_REQUEST["pid"]) && is_numeric(trim($_REQUEST["pid"]))){
    $postid=trim($_REQUEST["pid"]);   
}
if(isset($_REQUEST["ploc"]) && trim($_REQUEST["ploc"])!=""){
    $postLocationAdd=base64_decode(trim($_REQUEST["ploc"]));   
}
//echo $postLocationAdd;
?>
<!-- add location -->
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src='http://maps.google.com/maps/api/js?sensor=false&libraries=places'></script>
<script>
<?php
//ploc
        $latitude=0;
        $longitude=0;
        if(!empty($postLocationAdd)){
            // Get lat and long by address         
            $address =$postLocationAdd;
            $prepAddr = str_replace(' ','+',$address);
            $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
            $output= json_decode($geocode);
            $latitude = $output->results[0]->geometry->location->lat;
            $longitude = $output->results[0]->geometry->location->lng;
        }
        //46.15242437752303, longitude: 2.7470703125
        if(($latitude==0 || $longitude==0) || (!is_numeric($latitude) || !is_numeric($longitude)) ){
            $latitude=46.15242437752303;
            $longitude=-2.7470703125;
        }
?>
var tracedLocation={latitude:<?php echo $latitude; ?>,longitude:<?php echo $longitude; ?>};
</script>

<script src="js/locationpicker.jquery.js"></script>
</head>

<body>

<input type="hidden" id="editpostid" name="editpostid" value="0" />
<input type="text" id="txtlocationtemp1" name="txtlocationtemp1" style="width: 400px;height:25px" value=""/>
<input type="submit" value="Finish" onclick="setMyAddress();"/>
<div id="somecomponent1" style="width: 480px; height: 200px;"></div>

<script>
//ref: http://logicify.github.io/jquery-locationpicker-plugin/
//https://codeload.github.com/Logicify/jquery-locationpicker-plugin/zip/master

$('#somecomponent1').locationpicker({
    location: tracedLocation,	
    radius: 200,
    inputBinding: {
        //latitudeInput: $('#us2-lat'),
        //longitudeInput: $('#us2-lon'),
        //radiusInput: $('#us2-radius'),
        locationNameInput: $('#txtlocationtemp1')
    },
    enableAutocomplete: true,
    onchanged: function(currentLocation, radius, isMarkerDropped) {
       //alert("Location changed. New location (" + currentLocation.latitude + ", " + currentLocation.longitude + ")"+ currentLocation);
    }
});

function setMyAddress(){
    <?php
    if(!$isEditPost){
    ?>
        window.parent.document.getElementById("locstr").value=$('#txtlocationtemp1').val();
        window.parent.document.getElementById("post_location").innerHTML="&nbsp;Location: near to \""+$('#txtlocationtemp1').val()+"\"";
        window.parent.document.getElementById("post_location").style.display='block';
    <?php
    }else{
    ?>
    window.parent.setPostLocation($('#txtlocationtemp1').val(),<?php echo $postid; ?>);
    <?php    
    }
    ?>
    window.parent.lightbox_closeCurrent();
    //$(window).parent().find("#frmstupdt #post_location").html("&nbsp;Location: near to \""+$('#txtlocationtemp1').val()+"\"");
    //$(window).parent().find("#frmstupdt #post_location").show();
    //$( "#frmstupdt #post_location" ).html("&nbsp;Location: near to \""+$( "#frmlocupdt #txtlocation" ).val().trim()+"\"");
    //$( "#frmstupdt #post_location" ).show();
    //$("#ajx_status_update").focus();
}
</script>

</body>
</html>